package asia.lxq.cic.controller;

import asia.lxq.cic.entity.Result;
import asia.lxq.cic.service.UserService;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Result<Map<String,String>> login(@RequestBody Map<String,String> loginParam) throws Exception {
        return userService.login(loginParam);
    }

    @PostMapping("/register")
    @PermitAll
    public Result<Object> register(@RequestBody Map<String,String> registerParam) {
        return userService.register(registerParam);
    }

    @GetMapping("/oauth/logout")
    public Result<Object> logout() {
        return userService.logout();
    }

    @PostMapping("/refresh_token")
    public Result<Object> refreshToken(@RequestBody Map<String,String> param){
        return userService.refreshToken(param);
    }
}
